package ljl.codetop300;

public class _offer_04_search_in_matrix {

  public boolean findNumberIn2DArray(int[][] matrix, int target) {
    int m = matrix.length;
    if (m == 0) return false;
    int n = matrix[0].length;
    int i = 0, j = n - 1;
    while (i < m && j > -1) {
      int c = matrix[i][j];
      if (c > target) j--;
      else if (c < target) i++;
      else return true;
    }
    return false;
  }

}
